var SupplierModel = function (supplier, hasFilter) {
  BaseModel.call(this);

  var self = this;
  var filterFields = ['code', 'name'];
  var fn = {
    initData: function (supplier) {
      if (SysUtil.isEmpty(supplier)) {
        this.initSupplier();
      } else {
        this.setSupplier(supplier);
      }
    },

    initSupplier: function () {
      var fields = ['code', 'name', 'contact', 'paymentWay', 'phone', 'email', 'isTax', 'preight',
        'fax', 'address'
      ];
      self.initObject(fields);
    },

    setSupplier: function (supplier) {
      self.code = supplier.customerCode;
      self.name = supplier.customerName;

      var fields = ['id', 'contact', 'paymentWay', 'phone', 'email', 'isTax', 'preight', 'fax', 'address'];
      self.setDataFromObj(supplier, fields);
    }
  };

  this.checkValid = function () {
    var fields = ['code', 'name', 'contact', 'paymentWay'];
    var code = CheckVaildUtil.checkNullField(fields, this);
    return code;
  };

  this.getObject = function () {
    var postData = {
      customerCode: this.code,
      customerName: this.name,
      type: 1,
      status: '使用'
    };

    var fields = ['contact', 'paymentWay', 'phone', 'email', 'isTax', 'preight', 'fax', 'address'];
    this.setPostData(postData, fields);

    return postData;
  };

  if (hasFilter) {
    this.filterData = function (queryStr) {
      queryStr = queryStr.toLowerCase();
      for (var i = 0; i < filterFields.length; i++) {
        var field = filterFields[i];
        var value = this[field];
        value = value.toLowerCase();
        if (value.indexOf(queryStr) !== -1) {
          return true;
        }
      }
      return false;
    };
  }

  fn.initData(supplier);
};